package com.example.javamaday.leetcode;

import java.util.Comparator;
import java.util.HashMap;
import java.util.PriorityQueue;

public class LeetCodeTest0506 {

    public static void main(String[] args) {

    }

    public String[] findRelativeRanks(int[] score) {

        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(score.length, new Comparator<Integer>() {
            @Override
            public int compare(Integer integer, Integer t1) {
                return integer.compareTo(t1);
            }
        });
        for (int j : score) {
            priorityQueue.offer(j);
        }
        HashMap<Integer, Integer> rankMap = new HashMap<>();
        while (priorityQueue.size() > 0) {
            rankMap.put(priorityQueue.poll(), priorityQueue.size());
        }

        String[] result = new String[score.length];
        for (int i = 0; i < score.length; i++) {
            Integer rank = rankMap.get(score[i]);
            if (rank == 0) {
                result[i] = "Gold Medal";
            } else if (rank == 1) {
                result[i] = "Silver Medal";
            } else if (rank == 2) {
                result[i] = "Bronze Medal";
            } else {
                result[i] = "" + (rank + 1);
            }
        }
        return result;
    }
}
